//
//  TiXianPassWordViewController.m
//  Experss
//
//  Created by 嗯，大葱 on 17/8/8.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "TiXianPassWordViewController.h"
#import "LXCInputPasswordView.h"
#import "PayResultView.h"//支付结果视图



@interface TiXianPassWordViewController ()<payResultBackBtnDelegate,LXCInputPasswordViewDelegate>
{
    NSString *passWordStr;
}
@property (nonatomic, strong)PayResultView *payResultView;
@property (nonatomic, strong)LXCInputPasswordView *passView;
@end

@implementation TiXianPassWordViewController
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    _sureBtn.userInteractionEnabled = NO;
    if (_payResultView) {
        [_payResultView removeFromSuperview];
    }
 
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configureNaBar];
    
    _passView = [LXCInputPasswordView inputPasswordViewWithY:CGRectGetMaxY(_paLB.frame)+20];
    _passView.delegate = self;
    
    [self.view addSubview:_passView];
}

#pragma mark 密码输入框的代理事件
- (void)inputPasswordViewDelegate:(LXCInputPasswordView *)inputPasswordView inputEndWithPassword:(NSString *)inputEndWithPassword {
    
    NSLog(@"---%@",inputEndWithPassword);
    _sureBtn.selected = YES;
    _sureBtn.userInteractionEnabled = YES;
    passWordStr = inputEndWithPassword;
    
}

//小于6位不能确认按钮不能点击
- (void)inputPasswordXiaoYuSix {
    _sureBtn.selected = NO;
    _sureBtn.userInteractionEnabled = NO;
}



- (void)configureNaBar {
    
    
    if ([_typeStr isEqualToString:@"chaoshi"]) {
          self.navigationItem.title = @"支付密码";
        self.paLB.text = @"请输入支付密码完成提现";
    }
    if ([_typeStr isEqualToString:@"peisong"]) {
        self.navigationItem.title = @"提现";
        self.paLB.text = @"请输入提现密码完成提现";
    }
    
  
    //设置导航栏按钮的边距
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame= CGRectMake(0, 0, 60, 30);
    [rightBtn setImage:[UIImage imageNamed:@"all_fanhui2"] forState:(UIControlStateNormal)];
    [rightBtn addTarget:self action:@selector(handleBackAxtion) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *btn_left = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    UIBarButtonItem *negativeSpacerleft = [[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace   target:nil action:nil];
    /**
     width为负数时，相当于btn向右移动width数值个像素，由于按钮本身和  边界间距为5pix，所以width设为-5时，间距正好调整为0；width为正数 时，正好相反，相当于往左移动width数值个像素
     */
    negativeSpacerleft.width = -20;
    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacerleft, btn_left, nil];
    
}

- (void)handleBackAxtion {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



#pragma mark 确认提现
- (IBAction)sureTiXianBtnAction:(id)sender {
    
    NSDictionary *saveDic = [SaveDataMethord readLoginData];

    //超市端提现
    if ([_typeStr isEqualToString:@"chaoshi"]) {
           NSDictionary *parameDic = @{@"userid":saveDic[@"userid"],@"amount":_amountT,@"backcard_id":_backcard_idT,@"password":passWordStr,@"actoken":[Md5Apiway getMD5data:saveDic[@"userid"]]};
        [HttpRequest postWithURLString:POST(Shop_PersonalWithdraw) parameters:parameDic success:^(id responseObject) {
           
            
            if ([responseObject[@"ret"] intValue] != 200) {
                [MBProgressHUD showText:@"设置通知出错"];
                return ;
            }
            NSDictionary *tempD = responseObject[@"data"];
            
            if (![[NSString stringWithFormat:@"%@",tempD[@"code"]] isEqualToString:@"0"]) {
                [MBProgressHUD showText:tempD[@"msg"]];
                return;
            }
            
            if (_payResultView) {
                [_payResultView removeFromSuperview];
            }
            _payResultView = [[PayResultView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
            _payResultView.delegate = self;
            _payResultView.imageStr = @"tixianchengg";
            _payResultView.payResultStr = @"提现成功";
            _payResultView.detailStr = @"提现金额将在七个工作日到账";
            [[UIApplication sharedApplication].keyWindow addSubview:_payResultView];
            
            
        } failure:^(NSError *error) {
            
        }];
        
    }
    
    

    
    
}
- (void)payBackAction:(UIButton *)sender {
    if (_payResultView) {
        [_payResultView removeFromSuperview];
    }
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark 忘记密码
- (IBAction)forgetPasswordAction:(UIButton *)sender {
    
}

@end
